package com.haipumi.listeners;

import java.util.List;
import javax.servlet.ServletContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.web.context.support.WebApplicationObjectSupport;

import com.haipumi.beans.haipumi_customerService;
import com.haipumi.biz.CustomerServiceBiz;
import com.haipumi.utils.CommonData;

public class CustomerServiceListener extends WebApplicationObjectSupport implements ApplicationListener<ContextRefreshedEvent> {
	
	@Autowired
    private CustomerServiceBiz customerServiceBiz;
	private ServletContext servletContext;
	
    @Override
	protected void initServletContext(ServletContext servletContext) {
		this.servletContext=servletContext;
	}

	@Override
    public void onApplicationEvent(ContextRefreshedEvent ev) {

        //防止重复执行。
        if(ev.getApplicationContext().getParent() == null){
    		List<haipumi_customerService> list=customerServiceBiz.findAll();
        	servletContext.setAttribute(CommonData.CUSTOMERSERVICEKEY, list);
        	System.out.println(list);
        }
        
    }
 
}
